package com.bds.btcdc.adapter.okcoin.service;

import com.alibaba.fastjson.JSONObject;
import com.bds.btcdc.adapter.okcoin.OkCoinAPIClient;
import com.bds.btcdc.api.model.Result;
import org.apache.http.HttpException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.io.IOException;
import java.util.Map;

/**
 * Created by DongChenchen on 2018/5/9 0008
 * zb交易api
 */
@Service
public class OkCoinTradeService {
    private static final Logger logger = LoggerFactory.getLogger(OkCoinTradeService.class);


    public Result proxyOrder(Map<String, String> params) {
        return null;
    }

    /**
     * 获取资产情况      代码未写完。。。。
     * @param userId
     * @param accessKey
     * @param secretKey
     * @return
     */
    public Result getCapitalInfo(Long userId, String accessKey, String secretKey) throws IOException, HttpException {
        logger.info("获取资产情况。。。。。。。。。。。。。。");
        OkCoinAPIClient client = OkCoinAPIClient.getInstance(userId,accessKey, secretKey);
        String result = client.getAccountInfo();
        JSONObject jsonObj = JSONObject.parseObject(result);
        if(jsonObj.getBoolean("result")) {
            try {
                JSONObject info =jsonObj.getJSONObject("info");
                String funds = info.getString("funds");
            }catch (Exception e){
                e.printStackTrace();
            }
        }else{
        }
        return null;
    }



    /**
     * 参数校验，都不能为空
     *
     * @return
     */
    private boolean volidate(Map<String, String> args) {
        for (Map.Entry<String, String> entry : args.entrySet()) {
            if (StringUtils.isEmpty(entry.getValue())) {
                return false;
            }
        }
        return true;
    }
}
